<template>
	<view class="page index">
		<view class="form">
			<picker mode="selector" :value="complateIndex" :range="complate" @change="selectComplate">
				<view class="picker">
					<common-input
					  title="实施完成情况" 
						v-model="complate[complateIndex]"
						:border-bottom="false"
					>
					</common-input>
				</view>
			</picker>
			<common-input
			  title="已完成实施进度" 
				placeholder="请填写当前完成进度(0-100)" 
				v-model="progress"
				type="number"
			>
			</common-input>
			<view class="text">
				<view class="title">
					<view>
						实施进展情况说明
					</view>
					<view class="require"></view>
				</view>
				<textarea v-model="proExplain" placeholder="请输入" placeholder-class="place"></textarea>
			</view>
			<picker mode="selector" :value="levelIndex" :range="levelList" @change="selectLevel">
				<view class="picker">
					<common-input 
					  title="进度管控风险等级" 
					  placeholder="请选择风险等级" 
					  v-model="levelIndex < 0 ? '' : levelList[levelIndex]" 
					  :select="true" 
					  :disabled="true" 
						:boder-top="false"
					>
					</common-input>
				</view>
			</picker>
			<view class="text">
				<view class="title">
					<view>
						风险及问题说明
					</view>
					<view class="require"></view>
				</view>
				<textarea v-model="problemExplain" placeholder="请输入" placeholder-class="place"></textarea>
			</view>
			<view class="text">
				<view class="title">
					<view>
						下阶段实施计划说明
					</view>
					<!-- <view class="require"></view> -->
				</view>
				<textarea v-model="planExplain" placeholder="请输入" placeholder-class="place"></textarea>
			</view>
			<update-file @update="updatefiles"></update-file>
		</view>
		<view class="footer">
			<button @click="save">保存</button>
		</view>
	</view>
</template>

<script>
	import commonInput from "@/components/commonInput.vue";
	import updateFile from "@/components/updateFile.vue"
	import {createProgressApi} from "@/api/project_api.js"
	export default{
		data() {
			return{
				projectId: 0,
				complateIndex: 0,
				complate: ['未完成','已完成'],
				progress: '',
				proExplain: '',
				levelIndex: 0,
				levelList: ['四级（无超期风险）', '三级（较低可能超期）', '二级（较大可能超期）', '一级（已超期）'],
				problemExplain: '',
				planExplain: '',
				picUrls: '',
				fileUrls: ''
			}
		},
		components: {
			commonInput,
			updateFile
		},
		onLoad(e) {
			this.projectId = e.projectId;
		},
		methods:{
			selectComplate(e){
				this.complateIndex = e.detail.value;
			},
			selectLevel(e){
				this.levelIndex = e.detail.value
			},
			updatefiles(e){
				this.picUrls = e.filter((item) => {
					return item.type == 'image'
				});
				this.picUrls = this.picUrls.map((item) => item.path).join(',');
				this.fileUrls = e.filter((item) => {
					return item.type == 'file'
				});
				this.fileUrls = this.fileUrls.map((item) => item.path).join(',');
			},
			save(){
				if(this.progress == ''){
					uni.showToast({
						icon: 'none',
						title: '实施进度不能为空'
					})
					return;
				}
				if(this.proExplain == ''){
					uni.showToast({
						icon: 'none',
						title: '实施进展说明不能为空'
					})
					return;
				}
				if(this.problemExplain == ''){
					uni.showToast({
						icon: 'none',
						title: '风险及问题说明不能为空'
					})
					return;
				}
				uni.showLoading({
					mask: true,
					title: '加载中...'
				})
				createProgressApi({
					projectId: this.projectId,
					progress: this.progress,
					progressStatement: this.problemExplain,
					riskLevel: this.levelIndex,
					riskStatement: this.problemExplain,
					nextStageStatement: this.planExplain,
					picUrls: this.picUrls,
					fileUrls: this.fileUrls
				}).then(() => {
					uni.hideLoading();
					uni.showToast({
						icon: 'success',
						title: '创建成功！'
					})
					setTimeout(() => {
						uni.navigateBack();
					},1500)
				}).catch(() => {
					uni.hideLoading();
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	@import "@/common/style/customicons.scss";
	.index{
		padding: 24rpx 0;
		@include flex-c;
		.form{
			flex: 1 0 0;
			overflow: auto;
			.text{
				border-bottom: 4rpx #e5e5e5 solid;
				padding: 12rpx 30rpx;
				.title{
					font-size: 28rpx;
					color: #101010;
					padding: 0 0 16rpx;
					display: flex;
					align-items: center;
					.require{
					  height: 28rpx;
					  width: 6rpx;
					  background-color: #c24135;
					  margin-left: 10rpx;
				  }
				}
				textarea{
					font-size: 28rpx;
					color: #909090;
					height: 125rpx;
				}
				.place{
					font-size: 28rpx;
					color: #909090;
				}
			}
			&::-webkit-scrollbar{
				display: none;
			}
		}
		.footer{
			flex: 0 0 auto;
			padding: 24rpx 130rpx;
			button{
				@include button;
				background-color: #198AFA;
				color: #fff;
				height: 60rpx;
				line-height: 60rpx;
				font-size: 28rpx;
				width: 100%;
			}
		}
	}
</style>